package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "MyFilter",urlPatterns = "/register.do")
public class filter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletResponse.setContentType("text/html;charset=UTF-8");
        String username = servletRequest.getParameter("username");
        System.out.println("获取到的用户名: " + username);
        String password = servletRequest.getParameter("password");
        System.out.println("获取到的密码: " + password);


        servletResponse.getWriter().write("<br>");
        servletResponse.getWriter().write("用户名:"+username);
        servletResponse.getWriter().write("<br>");
        servletResponse.getWriter().write("密码:"+password);
        servletResponse.getWriter().write("<br>");

        if(password.length()>=8){
            servletResponse.getWriter().write("登录成功");
            filterChain.doFilter(servletRequest,servletResponse);
        }else {
            servletResponse.getWriter().write("密码未达到八位数,请重新登录");
        }
    }

    @Override
    public void destroy() {

    }
}
